"""
Django设置文件 for YyCloud项目。

由'django-admin startproject'生成，使用Django 5.0.6。

有关此文件的更多信息，请参阅
https://docs.djangoproject.com/en/5.0/topics/settings/

有关设置及其值的完整列表，请参阅
https://docs.djangoproject.com/en/5.0/ref/settings/
"""
# 导入os模块，用于操作操作系统功能
import os

# 导入pathlib模块，用于路径操作
from pathlib import Path

# 定义BASE_DIR变量，表示项目的基础目录
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

# 快速启动开发设置 - 不适合生产环境
# See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/
# 设置SECRET_KEY，用于加密 Django 中的各种数据
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-(u8^nj6*%ed3)#4mzy*02ug0y(#0#pn4_465lo-wx@rv^-nuyr'

# 设置DEBUG，表示是否开启调试模式
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

# 设置ALLOWED_HOSTS，表示允许的HTTP主机列表
ALLOWED_HOSTS = ["*"]
CORS_ORIGIN_ALLOW_ALL = True
# 允许域名加入白名单
# CORS_ORIGIN_WHITELIST = (
#     'http//:localhost:8000',
# )
SECURE_CROSS_ORIGIN_OPENER_POLICY = 'None'
# 应用定义
# 定义INSTALLED_APPS，表示安装的Django应用列表
INSTALLED_APPS = [
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'web.apps.WebConfig',
    'corsheaders'
]

# 定义MIDDLEWARE，表示使用的中间件列表
MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    # 'django.middleware.csrf.CsrfViewMiddleware',
    'corsheaders.middleware.CorsMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'web.Middleware.CloudShop.MD1',  # 云商中间件
]

# 定义ROOT_URLCONF，表示URL配置的模块
ROOT_URLCONF = 'YyCloud.urls'

# 定义TEMPLATES，表示模板引擎的配置
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

# 定义WSGI_APPLICATION，表示WSGI应用的配置
WSGI_APPLICATION = 'YyCloud.wsgi.application'

# 数据库配置
# https://docs.djangoproject.com/en/5.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'yycloud',
        'PASSWORD': '123456',
        'HOST': 'localhost',
        'PORT': 3306,
        'USER': 'root'
    }
}

# 密码验证配置
# https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# 国际化配置
# https://docs.djangoproject.com/en/5.0/topics/i18n/
LANGUAGE_CODE = 'zh-hans'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_TZ = True

# 静态文件配置
# https://docs.djangoproject.com/en/5.0/howto/static-files/
STATIC_URL = 'static/'

# 默认主键字段类型
# https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# 媒体文件配置
# 媒体文件的URL路径
MEDIA_URL = '/media/'
# 媒体文件在文件系统中的根目录
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# 发送邮件
# 网易邮箱 授权码: DRQAUSMEDQGTSXSZ
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
EMAIL_USE_TLS = False
EMAIL_HOST_USER = '18171759943@163.com'
EMAIL_HOST_PASSWORD = 'DRQAUSMEDQGTSXSZ'
EMAIL_USE_SSL = False  # 是否使用SSL加密，qq企业邮箱要求使用，163邮箱设置为True的时候会报ssl的错误
